package lab01;

import java.util.Scanner;

/**
 * Created by Administrator on 2017/9/24.
 */
public class Test08 {
    public static int random(){//1.获取随机数

        int number = (int)(Math.random()*100)+1;
        return number;
    }

    public static int cai(){//2.用户猜一个数字
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        return a;
    }

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int x = random();
        int count = 0;
        System.out.println("请猜一个1~100的数字：");
        int a = cai();

        while(true){

            if(a>x){
                count++;
                System.out.println("猜了"+count+"次");
                System.out.println("猜大了！");
                System.out.println("请再猜一个数字：");
                a = cai();
                continue;
            }

            if(a<x){
                count++;
                System.out.println("猜了"+count+"次");
                System.out.println("猜小了！");
                System.out.println("请再猜一个数字：");
                a = cai();
                continue;
            }

            if(a==x){
                count++;
                System.out.println("中了！");
                System.out.println("猜对了！");
                System.out.println("共猜了"+count+"次");
                break;
            }
        }




    }
}
